'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:FinanceFXxfpCtrl
 * @description
 * # FinanceFXxfpCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
    .controller('FinanceFXxfpCtrl', function ($scope, localStorageService, openApi, Util, $location, $routeParams, FormSubmit) {
        var id = $scope.process_id = $routeParams.id
        //  增值税普通发票,增值税专用发票,普通商业发票,其它
        $scope.payTypeList = [{
            key: "增值税普通发票",
            value: "增值税普通发票"
        }, {
            key: "增值税专用发票",
            value: "增值税专用发票"
        }];
        // 3%,6%,10%,13%,16%,其它
        $scope.rateList = [{
            key: "无",
            value: "无"
        }, {
            key: "1%",
            value: "1%"
        }, {
            key: "2%",
            value: "2%"
        }, {
            key: "3%",
            value: "3%"
        }, {
            key: "5%",
            value: "5%"
        }, {
            key: "6%",
            value: "6%"
        }, {
            key: "9%",
            value: "9%"
        }, {
            key: "10%",
            value: "10%"
        }, {
            key: "11%",
            value: "11%"
        }, {
            key: "13%",
            value: "13%"
        }, {
            key: "16%",
            value: "16%"
        }, {
            key: "17%",
            value: "17%"
        }, {
            key: "免税",
            value: "免税"
        }, {
            key: "其他",
            value: "其他"
        }];

        $scope.choosePeople = function () {
            Util.savaParamForReview($scope.param, id);
            $location.path("project/chooseproject");
        };

        $scope.submit = function (operationId) {
            // 底部类型end
            var options = {};
            // 流程id
            options.id = id;
            // 根据operationId判断是草稿还是提交
            options.operationId = operationId;
            options.urlParam = openApi.outputInvoice;
            options.param = angular.copy($scope.param, {});
            delete options.param.details
            FormSubmit.submit(options, $scope);
        };
        $scope.validate = function () {
            if (!$scope.param.projectName) {
                Util.Toast("请选择项目名称");
                return;
            }
            if (!$scope.param.invoiceType) {
                Util.Toast("请选择发票类型");
                return;
            }
            if (!$scope.param.taxRate) {
                Util.Toast("请选择税率");
                return;
            }
            if (!$scope.param.taxAmount) {
                if ($scope.param.taxAmount != 0) {
                    Util.Toast("请填写发票税额");
                    return;
                }
            } if (!$scope.param.totalAmount) {
                if ($scope.param.totalAmount != 0) {
                    Util.Toast("请填写发票金额");
                    return;
                }
            }

            if (!$scope.validation.passvalidation) {
                Util.Toast($scope.validation.tip);
                return;
            }
            return true;
        };
        var init = function () {
            // 获取回显的详细信息
            Util.getDetailData(id, function (data) {
                $scope.param = data;
                var projectinfo = localStorageService.get("projectinfo");
                localStorageService.remove("projectinfo");
                $scope.param = Object.assign({}, $scope.param, projectinfo);
            });
        };
        // 初始化
        init();
    });
